﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Xinkui.WebModel {
    public static class URLHelper {

        public static string HostPath {
            get {
                return CommonFramework.Utility.WebHelper.HostPath;
            }
        }

        public static string RootPath {
            get {
                return CommonFramework.Utility.WebHelper.WebPath;
            }
        }


        public static string Resource(string url) {
            return string.Format("{0}{1}/{2}", HostPath, RootPath, url);
        }

        public static string AdapterRoot(string url) {
            return string.Format("{0}{1}/{2}", HostPath, RootPath, url);
        }


        public static string LinkToHome() {
            return AdapterRoot("");
        }

        #region ShowRoom URL

        public static string LinkToShowRoom_Home(int companyid) {
            return AdapterRoot(string.Format("showroom/Default.aspx?com={0}", companyid));
        }

        public static string LinkToShowRoom_Company(int companyid) {
            return AdapterRoot(string.Format("showroom/Company.aspx?com={0}", companyid));
        }

        public static string LinkToShowRoom_Contact(int companyid) {
            return AdapterRoot(string.Format("showroom/Contact.aspx?com={0}", companyid));
        }

        public static string LinkTpShowRoom_ContactByProduct(int product) {

            return AdapterRoot(string.Format("ContactSupplier.aspx?act=p&ref={0}", product));
        }

        public static string LinkTpShowRoom_ContactByCompany(int companyId) {

            return AdapterRoot(string.Format("ContactSupplier.aspx?com={0}&act=c", companyId));
        }

        public static string LinkToShowRoom_ProductDetail(int companyid, int productId, string productName) {
            return AdapterRoot(string.Format("showroom/ProductDetail.aspx?com={0}&pro={1}", companyid, productId));
        }

        public static string LinkToShowRoom_ProductListForList(int companyid) {
            return AdapterRoot(string.Format("showroom/ProductListForList.aspx?com={0}", companyid));
        }

        public static string LinkToShowRoom_ProductListForImage(int companyid) {
            return AdapterRoot(string.Format("showroom/ProductListForImage.aspx?com={0}", companyid));
        }

        public static string LinkToShowRoom_ProductListForImage(int companyid, object paths, string key) {
            List<string> pathList = new List<string>(paths as List<string>);
            while (pathList.Count < 3) {
                pathList.Add("0");
            }
            for (int i = 0; i < pathList.Count; i++) {
                pathList[i] = string.Format("cat{0}={1}", i + 1, pathList[i]);
            }
            if (string.IsNullOrEmpty(key))
                return AdapterRoot(string.Format("showroom/ProductListForImage.aspx?com={0}&{1}", companyid, string.Join("&", pathList.ToArray())));

            else
                return AdapterRoot(string.Format("showroom/ProductListForImage.aspx?com={0}&{1}&k={2}", companyid, string.Join("&", pathList.ToArray()), key));
        }


        public static string LinkToShowRoom_ProductListForList(int companyid, object paths, string key) {
            List<string> pathList = new List<string>(paths as List<string>);
            while (pathList.Count < 3) {
                pathList.Add("0");
            }
            for (int i = 0; i < pathList.Count; i++) {
                pathList[i] = string.Format("cat{0}={1}", i + 1, pathList[i]);
            }
            if (string.IsNullOrEmpty(key))
                return AdapterRoot(string.Format("showroom/ProductListForList.aspx?com={0}&{1}", companyid, string.Join("&", pathList.ToArray())));
            else
                return AdapterRoot(string.Format("showroom/ProductListForList.aspx?com={0}&{1}&k={2}", companyid, string.Join("&", pathList.ToArray()), key));
        }


        #endregion

        #region Fore
        public static string LinkToLogin(string url) {
            string q = string.Empty;
            if (!string.IsNullOrEmpty(url)) {
                q = string.Format("?ref={0}", url);
            }
            return AdapterRoot(string.Format("login.aspx{0}", q));
        }

        public static string LinkToLogin() {
            return LinkToLogin(string.Empty);
        }

        public static string LinkToRegister() {
            return LinkToRegister(string.Empty);
        }

        public static string LinkToRegister(string url) {
            string q = string.Empty;
            if (!string.IsNullOrEmpty(url)) {
                q = string.Format("?ref={0}", url);
            }
            return AdapterRoot(string.Format("registerstep1.aspx{0}", q));
        }
        public static string LinkToPostBuyleads() {
            return AdapterRoot("postbuyleads.aspx");
        }

        public static string LinkToBuyleads() {
            return AdapterRoot("buyleads.aspx");
        }

        public static string LinkToSearchProducts() {
            return AdapterRoot("SearchProducts.aspx");
        }

        public static string LinkToSearchCompanys() {
            return AdapterRoot("SearchCompanys.aspx");
        }

        public static string LinkToSearchProducts(string keywords) {

            return LinkToSearchProducts() + "?k=" + keywords;
        }

        public static string LinkToSearchCompanys(string keywords) {

            return LinkToSearchCompanys() + "?k=" + keywords;
        }

        public static string LinkToBuyleadsDetail(int buyleadId) {
            return AdapterRoot(string.Format("buyleaddetail.aspx?buy={0}", buyleadId));
        }

        public static string LinkToCatalogProducts(int cat1, int cat2, int cat3) {
            return AdapterRoot(string.Format("catalogproducts.aspx?cat1={0}&cat2={1}&cat3={2}", cat1, cat2, cat3));
        }

        public static string LinkToCatalogCompanys(int cat1, int cat2, int cat3) {
            return AdapterRoot(string.Format("catalogcompany.aspx?cat1={0}&cat2={1}&cat3={2}", cat1, cat2, cat3));
        }

        public static string LinkToCatalogProducts(object paths) {
            List<string> pathList = new List<string>(paths as List<string>);
            while (pathList.Count < 3) {
                pathList.Add("0");
            }
            for (int i = 0; i < pathList.Count; i++) {
                pathList[i] = string.Format("cat{0}={1}", i + 1, pathList[i]);
            }
            return AdapterRoot(string.Format("catalogproducts.aspx?{0}", string.Join("&", pathList.ToArray())));
        }

        public static string LinkToCatalogCompanys(object paths) {
            List<string> pathList = new List<string>(paths as List<string>);
            while (pathList.Count < 3) {
                pathList.Add("0");
            }
            for (int i = 0; i < pathList.Count; i++) {
                pathList[i] = string.Format("cat{0}={1}", i + 1, pathList[i]);
            }
            return AdapterRoot(string.Format("catalogcompany.aspx?{0}", string.Join("&", pathList.ToArray())));
        }

        public static string LinkToSellChannel() {
            return AdapterRoot("catalogproducts.aspx");
        }


        #endregion
        #region UserCenter

        public static string LinkToUserCenter() {
            return AdapterRoot("usercenter/index.aspx");
        }

        public static string LinkToSendBox() {
            return AdapterRoot("usercenter/Sendbox.aspx");
        }

        public static string LinkToInBox() {
            return AdapterRoot("usercenter/Inbox.aspx");
        }

        public static string LinkToRecycle() {
            return AdapterRoot("usercenter/Recylebox.aspx");
        }

        public static string LinkToMsgDetail(int msgId, int type) {
            return AdapterRoot(string.Format("usercenter/msgdetail.aspx?Mt={0}&Msg={1}", type, msgId));
        }

        public static string LinkToCompanyInfo() {
            return AdapterRoot("usercenter/BasicInfo.aspx");
        }

        public static string LinkToCertificate() {
            return AdapterRoot("usercenter/ManagerCertificate.aspx");
        }

        public static string LinkToPostCertificate() {
            return AdapterRoot("usercenter/PostCertificate.aspx");
        }

        public static string LinkToPostCertificate(int id) {
            return AdapterRoot("usercenter/PostCertificate.aspx?e=" + id);
        }

        public static string LinkToEquipment() {
            return AdapterRoot("usercenter/ManagerEquipment.aspx");
        }

        public static string LinkToPostEquipment() {
            return AdapterRoot("usercenter/PostEquipment.aspx");
        }


        public static string LinkToPostEquipment(int id) {
            return AdapterRoot("usercenter/PostEquipment.aspx?idx=" + id);
        }

        public static string LinkToPostProduct() {
            return AdapterRoot("usercenter/PostProduct.aspx");
        }

        public static string LinkToPostProduct(int id) {
            return LinkToPostProduct() + "?e=" + id;
        }

        public static string LinkToManagerProduct() {
            return AdapterRoot("usercenter/ManagerProducts.aspx?status=5");
        }



        #endregion

    }
}
